<template>
  <!-- 安全制度分类 -->
  <base-breadcrumb>
    <div class="page-body">
      <a-card :bordered="false">
        <title-name title="安全制度管理" />
        <div class="table-operateors mb20">
          <a-button icon="plus" type="primary" @click="handleUpdate('add')">新增分类</a-button>
        </div>
        <s-table
          ref="table"
          size="default"
          rowKey="id"
          :columns="columns"
          :data="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
          :showPagination="false"
          :scroll="{y: 600}"
        >
          <template slot="enabled" slot-scope="text, record">
            <status-display
              :status-code="record.enabled"
              :status-map="{ true : {
            label: '可用',
            color: 'green'
          }, false: {
            label: '不可用',
            color: 'red'
          }}"
            />
          </template>
          <template slot="operator" slot-scope="text, record">
            <a class="base-btn" @click="handleUpdate('edit', record)">编辑</a>
          </template>
        </s-table>
      </a-card>
    </div>
    <!-- 更新弹窗 -->
    <update-classify
      v-if="visible.update"
      :init-data="childInitData"
      @cancel="visible.update = false"
      @confirm="handleUpdateConfirm"
    />
  </base-breadcrumb>
</template>

<script>
import StatusDisplay from '@/components/StatusDisplay'
import { getSystemClassifyList } from '@/api/safetySupervision/safetySystem.js'
import UpdateClassify from './UpdateClassify.vue'
import { STable } from '@/components'

const columns = [
  {
    title: '分类名称',
    dataIndex: 'name',
  },
  {
    title: '使用层级',
    dataIndex: 'levelTypeName',
  },
  {
    title: '状态',
    dataIndex: 'enabled',
    scopedSlots: { customRender: 'enabled' },
  },
  {
    title: ' 操作',
    dataIndex: 'operator',
    scopedSlots: { customRender: 'operator' },
  },
]
export default {
    name:'a'+Date.now(),  components: {
    STable,
    UpdateClassify,
    StatusDisplay,
  },
  data() {
    return {
      childInitData: {},
      visible: {
        update: false,
      },
      columns: columns,
      queryParam: {},
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        const [err, res] = await getSystemClassifyList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      },
    }
  },
  methods: {
    handleUpdateConfirm() {
      this.visible.update = false
      this.$refs.table.refresh(true)
    },
    handleUpdate(type, data = {}) {
      this.childInitData = {
        ...data,
        pageType: type,
      }
      this.visible.update = true
    },
  },
}
</script>

<style>
</style>
